<template>

	<view class="shoprate">
		<u-navbar title="商户费率" left-text="" @leftClick="onClickBack" :placeholder="true" :fixed="true"
			:safeAreaInsetTop="true" :border="true"></u-navbar>

		<view class="ScanCodeRate">
			<view class="modifyRate w-flex w-flex-between w-p-10">
				<text>扫码费率</text>
				<text class="modify" @click="modify(0)">修改</text>
			</view>
			<view>
				<view class="w-flex" style="border-top: 1px solid rgb(223, 226, 229);border-bottom: 1px solid rgb(223, 226, 229);">
					<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);"></view>
					<view class="w-flex w-flex-center tableWidth" style="width: 74%;">
						T+1费率
					</view>
				</view>
				<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
					<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
						<text>微信</text>
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 74%;">
						{{WeChatRate}}%
					</view>
				</view>
				<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
					<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
						<text>支付宝</text>
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 74%;">
						{{AlipayRate}}%
					</view>
				</view>
			</view>
						
		</view>
		<view class="UnionPayRate">
			<view class="modifyRate w-flex w-flex-between w-p-10">
				<text>银联二维码费率</text>
				<text class="modify" @click="modify(1)">修改</text>
			</view>
			
			<view>
				<view class="w-flex" style="border-top: 1px solid rgb(223, 226, 229);border-bottom: 1px solid rgb(223, 226, 229);">
					<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);"></view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
						<view class="w-center">
							<view>
								T+1费率
							</view>
							<view style="font-size: 12px;color: #999999;">
								(>1000元)
							</view>
						</view>
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;">
						<view class="w-center">
							<view>
								T+1费率
							</view>
							<view style="font-size: 12px;color: #999999;">
								(<=1000元)
							</view>
						</view>
					</view>
				</view>
				<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
					<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
						<text>信用卡</text>
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
						
						{{unionScan.t1Credit}}%
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;">
						{{unionScan2.t1Credit}}%
					</view>
				</view>
				<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
					<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
						<text>借记卡</text>
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
						<view class="w-center">
							<view>
								{{unionScan.t1Debit}}%
							</view>
							<view style="font-size: 12px;color: #999999;">
								<!-- ({{unionScan.Capping || 0}}元封顶) -->
							</view>
						</view>
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;">
						{{unionScan2.t1Debit}}%
					</view>
				</view>
			</view>
						
		</view>
		<view class="payCardRate">
			<view class="modifyRate w-flex w-flex-between w-p-10">
				<text>刷卡费率</text>
				<text class="modify" @click="modify(2)">修改</text>
			</view>
			
			<view>
				<view class="w-flex" style="border-top: 1px solid rgb(223, 226, 229);border-bottom: 1px solid rgb(223, 226, 229);">
					<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);"></view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
						T+1费率
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;">
						T+0费率
					</view>
				</view>
				<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);color: #999999;">
					<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
						卡类型
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
						标准费率
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
						标准费率
					</view>
					<!-- <view class="w-flex w-flex-center tableWidth" style="width: 24%;">
						提现手续费
					</view> -->
				</view>
				<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
					<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
						<text>信用卡</text>
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
						{{card.t1Credit}}%
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
						{{card.t0Credit}}%
					</view>
					<!-- <view class="w-flex w-flex-center tableWidth" style="width: 24%;">
						{{card.WithdrawalRate || 0}}元/笔
					</view> -->
				</view>
				<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
					<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
						<text>借记卡</text>
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
						<view class="w-center">
							<view>
								{{card.t1Debit}}%
							</view>
							<view style="font-size: 12px;color: #999999;">
								<!-- ({{card.Capping || 0}}元封顶) -->
							</view>
						</view>
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
						{{card.t0Debit}}%
					</view>
					<!-- <view class="w-flex w-flex-center tableWidth" style="width: 24%;">
						{{card.WithdrawalRate || 0}}元/笔
					</view> -->
				</view>
				<view class="w-flex" style="border-bottom: 1px solid rgb(223, 226, 229);">
					<view class="w-flex w-flex-center tableWidth" style="width: 26%;border-right: 1px solid rgb(223, 226, 229);">
						<text>境外卡</text>
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
						{{card.t1OverSee}}%
					</view>
					<view class="w-flex w-flex-center tableWidth" style="width: 37%;border-right: 1px solid rgb(223, 226, 229);">
						{{card.t0OverSee}}%
					</view>
					<!-- <view class="w-flex w-flex-center tableWidth" style="width: 24%;">
						{{card.WithdrawalRate || 0}}元/笔
					</view> -->
				</view>
			</view>
		</view>
					
		<view class="w-flex w-mt-20 w-flex-center">
			<text class="btnStyle" style="width: 90%;" @click="saveRate">保存</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				WeChatRate: 0,
				AlipayRate: 0,
				unionScan: {
					t1Credit: 0,
					t1Debit: 0,
					// t0Credit: 0,
					// t0Debit: 0,
					Capping:0
				},
				unionScan2: {
					t1Credit: 0,
					t1Debit: 0,
					// t0Credit: 0,
					// t0Debit: 0
				},
				card: {
					t1Credit: 0,
					t0Credit: 0,
					t1Debit: 0,
					t0Debit: 0,
					t1OverSee: 0,
					t0OverSee: 0,
					WithdrawalRate: 0
				},
				dataUserID: null
			}
		},
		onShow() {
			
			if (uni.getStorageSync("ScanCodeRate")) {
				this.WeChatRate = uni.getStorageSync("ScanCodeRate").WeChatRate
				this.AlipayRate = uni.getStorageSync("ScanCodeRate").AlipayRate
			}
			if (uni.getStorageSync("UnionPayRate")) {
				this.unionScan.t1Credit = uni.getStorageSync("UnionPayRate").t1Credit;
				this.unionScan.t1Debit = uni.getStorageSync("UnionPayRate").t1Debit;
				this.unionScan2.t1Credit = uni.getStorageSync("UnionPayRate").t1Credit_Scan2;
				this.unionScan2.t1Debit = uni.getStorageSync("UnionPayRate").t1Debit_Scan2;
			}
			if (uni.getStorageSync("payCard")) {
				this.card = uni.getStorageSync("payCard");
			}
			if (uni.getStorageSync("dataUserID")) {
				this.dataUserID = uni.getStorageSync("dataUserID")
			}
			
		},
		onLoad() {
			this.getRate()
		},
		methods: {
			onClickBack () {
				uni.navigateBack()
			},
			async getRate () {
				let params = {
					user_id: uni.getStorageSync("dataUserID"),
				}
				const res = await this.$API({url: '/api/user/user_rate', method:"GET", data: params})
				if (res.code === 1) {
					this.WeChatRate = res.data.weixin
					this.AlipayRate = res.data.alipay
					this.unionScan = res.data.unionScan
					this.unionScan2 = res.data.unionScan2
					this.card = res.data.card
					
					let ScanCodeRate = {
						WeChatRate: res.data.weixin,
						AlipayRate: res.data.alipay,
					}
					let UnionPayRate = {
						t1Debit: res.data.unionScan.t1Debit,
						t1Credit: res.data.unionScan.t1Credit,
						t1Debit_Scan2: res.data.unionScan2.t1Debit,
						t1Credit_Scan2: res.data.unionScan2.t1Credit,
					}
					uni.setStorageSync("payCard",res.data.card)
					uni.setStorageSync("UnionPayRate", UnionPayRate)
					uni.setStorageSync("ScanCodeRate", ScanCodeRate)
				}
			},
			async saveRate () {
				if(!this.dataUserID) {
					uni.showToast({
						icon: 'none',
						title: '当前商户未成功进件'
					})
					return
				}
				let params = {
					user_id: this.dataUserID,
					param: {
						weixin: this.WeChatRate,
						alipay: this.AlipayRate,
						unionScan: {
							t1Credit: this.unionScan.t1Credit,
							t1Debit: this.unionScan.t1Debit,
							t0Credit: 0,
							t0Debit: 0,
						},
						unionScan2: {
							t1Credit: this.unionScan2.t1Credit,
							t1Debit: this.unionScan2.t1Debit,
							t0Credit: 0,
							t0Debit: 0,
						},
						card: this.card,
					}
					
				}
				let params1 = this.$qs.stringify(params)
				const res = await this.$API({url: '/api/user/save_user_rate', method:"POST", data: params1})
				if (res.code === 1) {
					uni.showToast({
						icon: 'none',
						title: res.msg,
						mask: true,
						success: () => {
							setTimeout(()=>{
								uni.navigateBack()
							},1000)
							
						}
					})
				}
			},
			modify (type) {
				uni.navigateTo({
					url: './modifyRate?modifyType='+type
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.shoprate {
		padding-bottom: 30rpx;
	}
	page {
		background-color: #FFFFFF;
	}
	.modifyRate {
		background: #F1F1F1;
		padding: 20rpx;
		color: #999999;
		.modify {
			border-radius: 26rpx;
			color: #1678ff;
			border: 1px solid #1678ff;
			padding: 4rpx 20rpx;
		}
	}
	.tableWidth{
		height: 90rpx;
	}
	
		.btnStyle {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 45%;
			height: 70rpx;
			background: #1678ff;
			color: #FFFFFF;
			font-size: 12px;
			border-radius: 10rpx;
		}
	
</style>
